﻿package com.player;

import com.alibaba.fastjson.JSONObject;
import com.execaction.CmdTaskQueue;
import com.qy.DaoMgr;
import com.qy.bean.Option;
import com.qy.bean.UserInfo;
import com.qy.util.StaticData;
import com.qy.util.TimeUtil;


/**
 * 乘客用戶
 * 1需要保存用戶信息
 * 2.保存通道信息
 * @author lym
 */
public class CommonUser extends User{

	//用户信息
	public UserInfo userInfo;
	//需要同步的服务id
	private int syncServerId;
	
	public CommonUser() {
		super();
	}
	
	public CommonUser(CmdTaskQueue cmdTaskQueue) {
		super(cmdTaskQueue);
	}
	
	public boolean loadData(UserInfo userInfo) {
		this.userInfo = userInfo;
		return true;
	}
	


	public UserInfo getUserInfo() {
		return userInfo;
	}

	public void setUserInfo(UserInfo userInfo) {
		this.userInfo = userInfo;
	}
	
	public UserInfo createUserInfo(String openid){
		UserInfo userInfo = new UserInfo();
		userInfo.setThirdId(openid);
		userInfo.setUserType(StaticData.userType.COMMON_USER.getType());
		userInfo.setCreateDate(TimeUtil.getSysteCurTime());
		userInfo.setUserStatus(StaticData.userStatus.perfect_information.getType());
		userInfo.setOp(Option.Insert);
		DaoMgr.getUserInfoDao().createUserInfo(userInfo);
		return userInfo;
	}

	@Override
	public void save() {
		DaoMgr.getUserInfoDao().updateUserInfo(userInfo);
	}

	@Override
	public int getUserStatus() {
		return this.userInfo.getUserStatus();
	}

	@Override
	public int getID() {
		return this.userInfo.getId();
	}

	@Override
	public String getKey() {
		return this.userInfo.getId()+StaticData.first_split+StaticData.userType.COMMON_USER.getType();
	}

	@Override
	public int getUserType() {
		return this.userInfo.getUserType();
	}
	
	
	public int getSyncServerId() {
	    return syncServerId;
	}

	public void setSyncServerId(int syncServerId) {
	    this.syncServerId = syncServerId;
	}

	/**
	 * 同步坐标点
	 * @param orderId
	 * @param json
	 */
	public void syncPoint(int orderId,JSONObject json){
	    if(orderId==syncServerId){
		this.sendPacket(json);
	    }
	}

	@Override
	public String getOpenId() {
	    return this.userInfo.getThirdId();
	}

}
